package com.example.travel.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import cn.bmob.v3.Bmob;
import cn.bmob.v3.BmobUser;
import cn.bmob.v3.listener.SaveListener;
import com.example.travel.R;

public class LoginActivity extends AppCompatActivity {
    Button dengru;
    TextView zhuce;
    private EditText namea,mimaa;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bmob.initialize(this, "725506ecca6f5fd13ccdb5541cddf851");
        setContentView(R.layout.activity_login);
        namea=(EditText)this.findViewById(R.id.zhanghao);
        mimaa=(EditText)this.findViewById(R.id.mima);

        zhuce=(TextView) this.findViewById(R.id.zhuce);
        dengru=(Button)this.findViewById(R.id.dengru);
        dengru.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String etzhanghao=namea.getText().toString();
                String etmima=mimaa.getText().toString();
                User o=new User();
                o.setUsername(etzhanghao);
                o.setPassword(etmima);
                o.login(new SaveListener<User>() {
                    @Override
                    public void done(User user, cn.bmob.v3.exception.BmobException e) {

                        if (e == null) {
                            Toast.makeText(LoginActivity.this, "登入成功！", Toast.LENGTH_LONG).show();
                            Intent intent=new Intent();
                            intent.setClassName("com.example.travel","com.example.travel.activity.MyContactActivity");
                            startActivity(intent);
                            finish();



                        } else {
                            Toast.makeText(LoginActivity.this, "登入失败！", Toast.LENGTH_LONG).show();

                        }
                    }

                });
//                Intent intent=new Intent();
//                intent.setClassName("com.example.travel","com.example.travel.activity.MyContactActivity");
//                startActivity(intent);
//                finish();

            }

        });
        zhuce.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent();
                        intent.setClassName("com.example.travel","com.example.travel.activity.Main2Activity");
                startActivity(intent);
//                finish();
            }
        });
    }

    public static class User extends BmobUser {

    }
}
